var t = getApp(),
    s = t.requirejs("core");
t.requirejs("jquery"), t.requirejs("foxui");

Page({
    data: {
        showtab: "do",
        success: "",
        page: 1,
        winHeight: "", //窗口高度
        currentTab: 0, //预设当前项的值
        scrollLeft: 0, //tab标题的滚动条位置
        time: [],
        setintervaltime: null,
        list: {}
    },
    // 点击标题切换当前页时改变样式
    swichNav: function (e) {
        var that = this
        var cur = e.target.dataset.current;
        console.log(cur);
        that.setData({
            currentTab: cur,
            success: cur
        })
        s.post("groups/team", {
            success: cur,
            page: that.data.page,
            zczlstatus: 1
        }, ((e) => {
            console.log(e,111);
            clearInterval(this.data.setIntervaltime)
            let time = setInterval(() => {
                let arr1 = []
                for (let i = 0; i < e.list.length; i++) {
                    let star_time = e.list[i].starttime
                    let end_time = e.list[i].endtime
                    let arr = that.countDown(star_time, end_time)
                    arr1.push({
                        ...arr,
                        ...e.list[i]
                    })
                    if (e.list.length - 1 == i) {
                        that.setData({
                            list: arr1,
                            success: e.success
                        })
                    }
                }
            }, 1000)
            that.setData({
                setIntervaltime: time
            })
            // that.setData({
            //     list: e.list,
            //     success: e.success
            // })
        }))
    },
    // 滚动切换标签样式


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        var that = this;
        //  高度自适应
        wx.getSystemInfo({
            success: function (res) {
                var clientHeight = res.windowHeight,
                    clientWidth = res.windowWidth,
                    rpxR = 750 / clientWidth;
                var calc = clientHeight * rpxR - 180;
                that.setData({
                    winHeight: calc
                });
            }
        });
        s.post("groups/team", {
            success: 0,
            page: that.data.page,
            zczlstatus: 1
        }, ((e) => {
            let time = setInterval(() => {
                let arr1 = []
                for (let i = 0; i < e.list.length; i++) {
                    let star_time = e.list[i].starttime
                    let end_time = e.list[i].endtime
                    let arr = that.countDown(star_time, end_time)
                    arr1.push({
                        ...arr,
                        ...e.list[i]
                    })
                    if (e.list.length - 1 == i) {
                        that.setData({
                            list: arr1
                        })
                    }
                }
            }, 1000)
            that.setData({
                setIntervaltime: time
            })
        }))
    },
    countDown: function (t, a) {
        var o = parseInt(Date.now() / 1e3),
            s = parseInt((t > o ? t : a) - o),
            i = Math.floor(s / 86400),
            d = Math.floor((s - 24 * i * 60 * 60) / 3600),
            n = Math.floor((s - 24 * i * 60 * 60 - 3600 * d) / 60),
            r = Math.floor(s - 24 * i * 60 * 60 - 3600 * d - 60 * n);
        0 == i && 0 == d && 0 == n && 0 == r && this.get_details(this.data.teamid);
        var u = {
            iay: i,
            day: d,
            nay: n,
            ray: r,
        }
        return u

    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        clearInterval(this.data.setIntervaltime)
        wx.navigateBack({
            delta: 1,
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    // onShareAppMessage: function () {

    // }
})